<template>
  <div class="comment-text">
    <textarea
      class="text"
      rows="6"
      :value="value"
      @input="$emit('input', $event.target.value)"
      :placeholder="ph"
    ></textarea>
    <span class="tip">还可输入{{ count - value.length }}字</span>
  </div>
</template>

<script>
export default {
  name: 'comment-text',
  props: {
    value: {
      type: String,
      default: ''
    }
  },
  watch: {
    value (newVal, oldVal) {
      if (newVal.length > this.count) this.$emit('input', oldVal)
    }
  },
  data () {
    return {
      ph: '宝贝是否满足了你的期待？说说你的使用心得分享给其它想购买的朋友吧。',
      count: 500
    }
  }
}
</script>

<style scoped lang='less'>
.comment-text {
  position: relative;
  .text {
    appearance: none;
    resize: none;
    border: 1px solid #e4e4e4;
    outline: none;
    padding: 10px;
    line-height: 28px;
    width: 100%;
    &::placeholder {
      color: #999;
    }
  }
  .tip {
    position: absolute;
    right: 10px;
    bottom: 10px;
    color: #666;
  }
}
</style>
